package com.ssl.product.controller;

import com.ssl.common.response.CommonResponse;
import com.ssl.common.response.ResponseUtils;
import com.ssl.product.pojo.ShoppingCarts;
import com.ssl.product.service.ShoppingCartsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 购物车
 */
@RestController
@RequestMapping("/shopping/carts")
public class ShoppingCartsController {
    @Autowired
    private ShoppingCartsService shoppingCartsService;

    /**
     * MongoDB 版购物车
     */

    @RequestMapping("/addOrUpdate")
    public CommonResponse addOrUpdate(@RequestBody ShoppingCarts shoppingCarts) {
        return ResponseUtils.okResponse(shoppingCartsService.addOrUpdate(shoppingCarts));
    }

    @RequestMapping("/delete")
    public CommonResponse delete(@RequestBody ShoppingCarts shoppingCarts) {
        return ResponseUtils.okResponse(shoppingCartsService.delete(shoppingCarts));
    }

    @RequestMapping("/search")
    public CommonResponse search(@RequestHeader String personId) {
        return ResponseUtils.okResponse(shoppingCartsService.search(personId));
    }

    /**
     * redis 版购物车
     */
    @RequestMapping("/redis/addOrUpdate")
    public CommonResponse addOrUpdateRedis(@RequestBody ShoppingCarts shoppingCarts) {
        return ResponseUtils.okResponse(shoppingCartsService.addOrUpdateRedis(shoppingCarts));
    }

    @RequestMapping("/redis/delete")
    public CommonResponse deleteRedis(@RequestBody ShoppingCarts shoppingCarts) {
        return ResponseUtils.okResponse(shoppingCartsService.deleteRedis(shoppingCarts));
    }

    @RequestMapping("/redis/search")
    public CommonResponse searchRedis(@RequestHeader String personId) {
        return ResponseUtils.okResponse(shoppingCartsService.searchRedis(personId));
    }
}
